package action;

import java.util.HashMap;
import java.util.List;

import model.PtManage;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import service.PtManageService;
import action.base.BaseAction;

@Controller
@Scope("prototype")
public class PtManageAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private PtManageService ptManageService;
	private boolean success = false;
	private PtManage ptManage;
	private List<HashMap<String, Object>> list;
	private List<PtManage> ptList;

	/**
	 * 列表中的树形结构
	 * 
	 * @return
	 */
	public String queryTree() {
		Integer id = getParameterInt("node");
		setList(ptManageService.queryTree(id));
		return "list";
	}

	/**
	 * 新增修改的树形结构
	 * 
	 * @return
	 */
	public String getTreeBypid() {
		setPtList(ptManageService.getTreeBypid(0));
		return "ptList";
	}

	/**
	 * 搜索Combobox
	 * 
	 * @return
	 */
	public String getByPid() {
		String flag = super.getParameterStr("flag");
		setPtList(ptManageService.getByPid(0));
		if (StringUtils.isNotBlank(flag) && flag.equals("search")) {
			PtManage pt = new PtManage();
			pt.setId(0);
			pt.setName("全部");
			ptList.add(pt);
		}
		return "ptList";
	}

	/**
	 * 保存单位信息
	 * 
	 * @return
	 */
	public String saveOrUpdate() {
		ptManageService.saveOrUpdate(ptManage);
		success = true;
		return "success";
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public PtManage getPtManage() {
		return ptManage;
	}

	public void setPtManage(PtManage ptManage) {
		this.ptManage = ptManage;
	}

	public List<HashMap<String, Object>> getList() {
		return list;
	}

	public void setList(List<HashMap<String, Object>> list) {
		this.list = list;
	}

	public List<PtManage> getPtList() {
		return ptList;
	}

	public void setPtList(List<PtManage> ptList) {
		this.ptList = ptList;
	}

}
